#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>

using namespace std;

int dx[8] = { 0 , 0 , 1 , -1 , 1 , -1 , -1, 1 };
int dy[8] = { 1, -1 , 0 , 0, 1 , -1, 1, -1 };
int m, n;


vector<vector<char>> updateBoard(vector<vector<char>>& board, vector<int>& click) {
    m = board.size();
    n = board[0].size();

    int i = click[0], j = click[1];

    dfs(board, i, j);

    return board;
}

void dfs(vector<vector<char>>& board, int i, int j)
{
    if (board[i][j] == 'M')
    {
        board[i][j] = 'X';
        return;
    }

    int num = 0;
    for (int k = 0; k < 8; ++k)
    {
        int x = i + dx[k];
        int y = j + dy[k];
        if (x >= 0 && x < m && y >= 0 && y < n && board[x][y] == 'M')
            num++;
    }

    if (num == 0)
    {
        board[i][j] = 'B';
        for (int k = 0; k < 8; ++k)
        {
            int x = i + dx[k];
            int y = j + dy[k];
            if (x >= 0 && x < m && y >= 0 && y < n && board[x][y] == 'E')
                dfs(board, x, y);
        }
    }
    else
    {
        board[i][j] = num + '0';
    }

}

int main()
{

	return 0;
}